
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/10/2011 09:56:16
-- Generated from EDMX file: E:\Nirosh\RandD\Rocket Framework\Rocket.Windows.Framework\Demo.Data\RocketModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Rocket_Core];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ReaderApplicationQuestion_Question]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReaderApplicationQuestion] DROP CONSTRAINT [FK_ReaderApplicationQuestion_Question];
GO
IF OBJECT_ID(N'[dbo].[FK_ReaderApplicationQuestion_ReaderApplication]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReaderApplicationQuestion] DROP CONSTRAINT [FK_ReaderApplicationQuestion_ReaderApplication];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Question]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Question];
GO
IF OBJECT_ID(N'[dbo].[ReaderApplication]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReaderApplication];
GO
IF OBJECT_ID(N'[dbo].[ReaderApplicationQuestion]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReaderApplicationQuestion];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Questions'
CREATE TABLE [dbo].[Questions] (
    [QuestionId] int  NOT NULL,
    [Text] varchar(16)  NOT NULL
);
GO

-- Creating table 'ReaderApplications'
CREATE TABLE [dbo].[ReaderApplications] (
    [ReaderApplicationId] int IDENTITY(1,1) NOT NULL,
    [Code] nchar(3)  NULL,
    [Name] varchar(150)  NOT NULL,
    [AddedDate] datetime  NOT NULL
);
GO

-- Creating table 'ReaderApplicationQuestions'
CREATE TABLE [dbo].[ReaderApplicationQuestions] (
    [ApplicationQuestionId] int IDENTITY(1,1) NOT NULL,
    [ReaderApplicationId] int  NOT NULL,
    [QuestionId] int  NOT NULL,
    [IsRepeating] bit  NOT NULL,
    [AcceptedAnswerCode] int  NOT NULL,
    [AnswerValidationCode] int  NOT NULL,
    [SendDefaultAnswer] bit  NOT NULL,
    [Sequence] int  NOT NULL,
    [IsLastQuestion] bit  NOT NULL,
    [WaitingCount] int  NULL,
    [AdditionalData] varchar(250)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [QuestionId] in table 'Questions'
ALTER TABLE [dbo].[Questions]
ADD CONSTRAINT [PK_Questions]
    PRIMARY KEY CLUSTERED ([QuestionId] ASC);
GO

-- Creating primary key on [ReaderApplicationId] in table 'ReaderApplications'
ALTER TABLE [dbo].[ReaderApplications]
ADD CONSTRAINT [PK_ReaderApplications]
    PRIMARY KEY CLUSTERED ([ReaderApplicationId] ASC);
GO

-- Creating primary key on [ApplicationQuestionId] in table 'ReaderApplicationQuestions'
ALTER TABLE [dbo].[ReaderApplicationQuestions]
ADD CONSTRAINT [PK_ReaderApplicationQuestions]
    PRIMARY KEY CLUSTERED ([ApplicationQuestionId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [QuestionId] in table 'ReaderApplicationQuestions'
ALTER TABLE [dbo].[ReaderApplicationQuestions]
ADD CONSTRAINT [FK_ReaderApplicationQuestion_Question]
    FOREIGN KEY ([QuestionId])
    REFERENCES [dbo].[Questions]
        ([QuestionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReaderApplicationQuestion_Question'
CREATE INDEX [IX_FK_ReaderApplicationQuestion_Question]
ON [dbo].[ReaderApplicationQuestions]
    ([QuestionId]);
GO

-- Creating foreign key on [ReaderApplicationId] in table 'ReaderApplicationQuestions'
ALTER TABLE [dbo].[ReaderApplicationQuestions]
ADD CONSTRAINT [FK_ReaderApplicationQuestion_ReaderApplication]
    FOREIGN KEY ([ReaderApplicationId])
    REFERENCES [dbo].[ReaderApplications]
        ([ReaderApplicationId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReaderApplicationQuestion_ReaderApplication'
CREATE INDEX [IX_FK_ReaderApplicationQuestion_ReaderApplication]
ON [dbo].[ReaderApplicationQuestions]
    ([ReaderApplicationId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------